package com.pureut.storage.controller;

import com.pureut.storage.service.StockOutInfoService;
import com.pureut.storage.vo.*;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 生产领料控制层
 * @author: CM
 * @date: 2023/7/17  11:21
 */

@RestController
@RequestMapping("/stockOutInfo")
public class StockOutInfoController extends BaseController {

    @Resource
    StockOutInfoService stockOutInfoService;

    /**
     * 新增生产领料单
     */
    //@SaCheckPermission("warehouse:outbound:producfield:add")
    @Log(title = "生产领料", businessType = BusinessType.INSERT)
    @PostMapping("/addPincking")
    public R<Void> add(@RequestBody ProductionPickingVo productionPickingVo) throws Exception {
        return toAjax(stockOutInfoService.addProductionPicking(productionPickingVo));
    }

    /**
     * 查询生产领料列表
     */
    //@SaCheckPermission("warehouse:outbound:producfield:list")
    @GetMapping("/list")
    public TableDataInfo getList(ProductionPickingVo productionPickingVo,PageQuery pageQuery) throws Exception {
        //查询拣货方案列表
        return stockOutInfoService.getList(productionPickingVo,pageQuery);
    }

    /**
     * 生产确认
     */
    //@SaCheckPermission("warehouse:outbound:producfield:confirm")
    @Log(title = "生产领料", businessType = BusinessType.UPDATE)
    @GetMapping("/confirm/{id}")
    public R<Void> confirm(@PathVariable("id") Long id) throws Exception {
        return toAjax(stockOutInfoService.confirm(id));
    }

    /**
     * 修改单据
     */
    //@SaCheckPermission("warehouse:outbound:producfield:edit")
    @Log(title = "修改单据", businessType = BusinessType.UPDATE)
    @PostMapping("/updateDoc")
    public R<Void> updateDoc(@RequestBody ProductionPickingVo productionPickingVo) throws Exception {
        return toAjax(stockOutInfoService.updateDoc(productionPickingVo));
    }

    /**
     * 查看单据
     */
    //@SaCheckPermission("warehouse:outbound:producfield:query")
    @GetMapping("/view/{id}")
    public R<?> view(@PathVariable("id") Long id) throws Exception {
        return R.ok(stockOutInfoService.view(id));
    }

    /**
     * 删除单据
     */
    //@SaCheckPermission("warehouse:outbound:producfield:remove")
    @Log(title = "删除单据", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteDoc/{ids}")
    public R<Void> deleteDoc(@PathVariable("ids") String ids) throws Exception {
        return toAjax(stockOutInfoService.deleteDoc(ids));
    }

    /**
     * 关结单据
     */
    //@SaCheckPermission("warehouse:outbound:producfield:close")
    @Log(title = "关结单据", businessType = BusinessType.UPDATE)
    @PostMapping("/closeDoc")
    public R<Void> closeDoc(@RequestBody ProductionPickingVo productionPickingVo) throws Exception {
        return toAjax(stockOutInfoService.closeDoc(productionPickingVo));
    }

    /**
     * 生产领料出库
     */
    //@SaCheckPermission("warehouse:outbound:producfield:outbound")
    @Log(title = "生产领料出库", businessType = BusinessType.UPDATE)
    @PostMapping("/out")
    public R<?> out(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(stockOutInfoService.out(pickingRestDbVo));
    }

    /**
     * 拣货完成
     */
    @GetMapping("/finishProduction/{id}")
    @Log(title = "生产领料-拣货完成", businessType = BusinessType.UPDATE)
    public R<?> finishProduction(@PathVariable("id") Long id) throws Exception {
        return R.ok(stockOutInfoService.finishProduction(id));
    }

    /**
     * 拣货撤销
     */
    @GetMapping("/repealProduction/{id}")
    @Log(title = "生产领料-拣货撤销", businessType = BusinessType.UPDATE)
    public R<?> repealProduction(@PathVariable("id") Long id) throws Exception {
        return R.ok(stockOutInfoService.repealProduction(id));
    }

    /**
     * 出库交接
     */
    //@SaCheckPermission("warehouse:outbound:producfield:handover")
    @Log(title = "生产领料-出库交接", businessType = BusinessType.UPDATE)
    @PostMapping("/overProduction")
    public R<?> overProduction(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(stockOutInfoService.overProduction(pickingRestDbVo));
    }


    /**
     * 拣货提示
     */
    @GetMapping("/point/{id}")
    public R<?> point(@PathVariable("id") Long id) throws Exception {
        return R.ok(stockOutInfoService.point(id));
    }

    /**
     * 全局拣货提示
     */
    @GetMapping("/getSchemePdaInfo")
    public R<?> getSchemePdaInfo(SchemePdaVo schemePdaVo) throws Exception {
        return R.ok(stockOutInfoService.getSchemePdaInfo(schemePdaVo));
    }

}
